package com.wdt.data.util;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class R extends HashMap {
    private static final long serialVersionUID = 1L;

    public R() {
        put("responseCode", 0);
        put("responseMsg", "success");
        put("responseTime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    public static R error() {
        return error(1, "未知异常，请联系管理员");
    }

    public static R error(String msg) {
        return error(2, msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.put("responseCode", code);
        r.put("responseMsg", msg);
        return r;
    }

    public static R ok() {
        return new R();
    }

    public static R ok(String msg) {
        R r = new R();

        r.put("responseMsg", msg);
        return r;
    }

    public static R ok(Map map) {
        R r = new R();
        r.remove("responseCode");
        r.remove("responseTime");
        r.putAll(map);
        r.put("responseMsg","success");
        return r;
    }

    public static R ok(List list) {
        R r = new R();
        r.put("data", list);
        return r;
    }
    public static R ok(String requestId,String responseCode,String responseMsg) {
        R r = new R();
        r.put("requestId",requestId);
        r.put("responseCode",responseCode);
        r.put("responseMsg",responseMsg);
        r.put("responseTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return r;
    }

    public static R ok(String requestId, String heatCompanyId,String responseCode,String responseMsg) {
        R r = new R();
        r.put("requestId",requestId);
        r.put("heatCompanyId",heatCompanyId);
        r.put("responseCode",responseCode);
        r.put("responseMsg",responseMsg);
        r.put("responseTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return r;
    }
    public static R ok(String requestId, String heatCompanyId,String responseCode,String responseMsg,List list) {
        R r = new R();
        r.put("requestId",requestId);
        r.put("heatCompanyId",heatCompanyId);
        r.put("responseCode",responseCode);
        r.put("responseMsg",responseMsg);
        r.put("responseTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        r.put("data",list);
        return r;
    }

}
